package main.model.hexisland;

import main.model.hexisland.tile.Tile;
import main.model.hexisland.tile.TileFactory;
import main.model.hexisland.tile.TileType;

import java.util.Random;

public class RandomHexIslandCreator {
	
	static HexIsland hexIsland;
	static Random r = new Random();
	
	public static HexIsland createRandomHexIsland(){
		return createRandomHexIsland(hexIsland.getQSize(), hexIsland.getRSize());
	}
	
	public static HexIsland createRandomHexIsland(int q, int r){
		hexIsland = new DefaultHexIsland(q , r);
		for(int q_count = 0; q_count < hexIsland.getQSize(); q_count++){
			for(int r_count = 0; r_count < hexIsland.getRSize(); r_count++){
				Tile tile = TileFactory.newTile(getRandomTileType());
				hexIsland.setTile(q_count, r_count, tile);

				//System.out.println("Rand x "+q_count+", y "+r_count+", g "+hexIsland.getTile(q_count,r_count));
			}
		}
		return hexIsland;
	}
	
	
	/**
	 * Chooses a GridType at random.
	 * <p>
	 * Chooses with probabilities of sand half, grass a quarter, tree a quarter.
	 * @return
	 */
	public static TileType getRandomTileType(){
		TileType type;
		if(r.nextInt(2) == 0){
			if(r.nextInt(3) == 0) type = TileType.TREE;
			else type = TileType.GRASS;
		}else{
            if(r.nextInt(4) == 0) {
                if(r.nextInt(2) == 0) type = TileType.WATER;
                else type = TileType.ROCK;
            }
            else type = TileType.SAND;
        }
		return type;
	}
}
